export default function (res) {
    const { query } = res;

    // Since req_body_is_json_schema is false, we only validate query parameters.
    // Validate 'receiptId' query parameter
    if (!query || !query.receiptId) {
        return new Promise((resolve) => {
            resolve({
                code: 1,
                message: '缺少必填查询参数：receiptId',
            });
        });
    }

    return new Promise((resolve) => {
        setTimeout(() => {
            const receiptId = query.receiptId;
            const studentId = Math.floor(Math.random() * 10000);
            const trainerId = Math.floor(Math.random() * 500);

            const grades = [
                "一年级", "二年级", "三年级", "四年级", "五年级", "六年级",
                "初一", "初二", "初三", "初四",
                "高一", "高二", "高三",
                "大一", "大二", "大三", "大四", "大四以上"
            ];
            const randomGrade = grades[Math.floor(Math.random() * grades.length)];

            const actualStartTime = new Date(Date.now() - Math.floor(Math.random() * 7) * 24 * 60 * 60 * 1000 - Math.floor(Math.random() * 3) * 60 * 60 * 1000); // Up to 7 days and 3 hours ago
            const durationMinutes = Math.floor(Math.random() * 60) + 30; // 30 to 90 minutes
            const actualEndTime = new Date(actualStartTime.getTime() + durationMinutes * 60 * 1000);

            // Generate random lesson learning summary data
            const lessonLearningSummary = {
                vocabularyDuration: Math.floor(Math.random() * 600) + 60, // 60-660 seconds
                shorthandDuration: Math.floor(Math.random() * 1200) + 300, // 300-1500 seconds
                shorthandWordNum: Math.floor(Math.random() * 50) + 10, // 10-60 words
                shorthandSpeed: Math.floor(Math.random() * 10) + 1, // 1-10 words/minute
                communicationDuration: Math.floor(Math.random() * 300) + 60, // 60-360 seconds
            };

            // Generate random unit learning summary data
            const unitLearningSummary = Array.from({ length: Math.floor(Math.random() * 3) + 1 }, (_, unitIndex) => {
                const numUnitDetails = Math.floor(Math.random() * 3) + 1; // 1-3 unit study details
                return {
                    courseName: `课程名称 ${unitIndex + 1}`,
                    unitStudyDetail: Array.from({ length: numUnitDetails }, (_, detailIndex) => ({
                        unit: {
                            no: (unitIndex * 10) + detailIndex + 1,
                            name: `单元 ${unitIndex + 1}.${detailIndex + 1}`,
                        },
                        studyDuration: Math.floor(Math.random() * 600) + 120, // 120-720 seconds
                        studyWordNum: Math.floor(Math.random() * 30) + 5, // 5-35 words
                        learningDurationPerWord: Math.floor(Math.random() * 20) + 5, // 5-25 seconds/word
                        preExamineDuration: Math.floor(Math.random() * 180), // 0-180 seconds
                        preExamineWordNum: Math.floor(Math.random() * 20), // 0-20 words
                        shortHandDuration: Math.floor(Math.random() * 300) + 60, // 60-360 seconds
                        shortHandWordNum: Math.floor(Math.random() * 25) + 5, // 5-30 words
                        shortHandDurationPerWord: Math.floor(Math.random() * 15) + 3, // 3-18 seconds/word
                        postExamineDuration: Math.floor(Math.random() * 240) + 30, // 30-270 seconds
                        postExamineWordNum: Math.floor(Math.random() * 20) + 5, // 5-25 words
                        postExamineScore: Math.floor(Math.random() * 101), // 0-100
                    })),
                };
            });

            // Generate random group learning summary data
            const groupLearningSummary = Array.from({ length: Math.floor(Math.random() * 2) + 1 }, (_, groupCourseIndex) => {
                const numUnitGroupLearningDetails = Math.floor(Math.random() * 2) + 1; // 1-2 unit group learning details
                return {
                    courseName: `分组课程名称 ${groupCourseIndex + 1}`,
                    unitLearningSummary: Array.from({ length: numUnitGroupLearningDetails }, (_, unitGroupIndex) => ({
                        unit: {
                            no: (groupCourseIndex * 5) + unitGroupIndex + 1,
                            name: `分组单元 ${groupCourseIndex + 1}.${unitGroupIndex + 1}`,
                        },
                        studyDuration: Math.floor(Math.random() * 500) + 100, // 100-600 seconds
                        studyWordNum: Math.floor(Math.random() * 20) + 5, // 5-25 words
                        learningDurationPerWord: Math.floor(Math.random() * 18) + 4, // 4-22 seconds/word
                        groupLearningDetail: Array.from({ length: Math.floor(Math.random() * 3) + 1 }, (_, groupDetailIndex) => ({
                            group: [groupDetailIndex + 1],
                            studyDuration: Math.floor(Math.random() * 400) + 80, // 80-480 seconds
                            studyWordNum: Math.floor(Math.random() * 15) + 3, // 3-18 words
                            learningDurationPerWord: Math.floor(Math.random() * 12) + 2, // 2-14 seconds/word
                            wordClickDuration: Math.floor(Math.random() * 60), // 0-60 seconds
                            wordListenDuration: Math.floor(Math.random() * 60), // 0-60 seconds
                            paperCutDuration: Math.floor(Math.random() * 60), // 0-60 seconds
                        })),
                    })),
                };
            });


            resolve({
                "code": 0,
                "message": "请求成功",
                "data": {
                    "student": {
                        "id": 257,
                        "name": "不知道",
                        "sn": "335768704520170",
                        "grade": "初二",
                        "school": "",
                        "trainAccount": false
                    },
                    "grade": "初二",
                    "actuallyStartTime": "2025-07-17 11:04:00",
                    "actuallyEndTime": "2025-07-17 11:07:00",
                    "duration": 3,
                    "trainer": {
                        "id": 32,
                        "name": "史蒂夫",
                        "account": "shidifu",
                        "deliveryGroupId": 10004
                    },
                    "wordScore": 1,
                    "lessonLearningSummary": {
                        "vocabularyDuration": null,
                        "shorthandDuration": 95,
                        "shorthandWordNum": 10,
                        "shorthandSpeed": 288,
                        "durationPerWord": 0,
                        "communicationDuration": null
                    },
                    "courses": [
                        {
                            "courseName": "初中单词体验",
                            "units": [
                                {
                                    "unit": {
                                        "no": 2,
                                        "name": "初中初级体验单元2"
                                    },
                                    "studyDuration": 95,
                                    "communicationDuration": null,
                                    "studyWordIds": [
                                        6576,
                                        304,
                                        3412,
                                        2725,
                                        792,
                                        1898,
                                        6779,
                                        2653,
                                        239,
                                        1743
                                    ],
                                    "studyWordNum": 10,
                                    "learningDurationPerWord": 0,
                                    "preExamineDuration": 28,
                                    "preExamineWordNum": 10,
                                    "shorthandDuration": 57,
                                    "shorthandWordNum": 10,
                                    "shorthandDurationPerWord": 0,
                                    "postExamineDuration": 10,
                                    "postExamineWordNum": 10,
                                    "postExamineScore": 90,
                                    "groups": [
                                        {
                                            "group": [
                                                1
                                            ],
                                            "studyDuration": 26,
                                            "studyWordNum": 5,
                                            "learningDurationPerWord": 0,
                                            "wordClickDuration": 9,
                                            "wordListenDuration": 6,
                                            "paperCutDuration": 11
                                        },
                                        {
                                            "group": [
                                                2
                                            ],
                                            "studyDuration": 20,
                                            "studyWordNum": 5,
                                            "learningDurationPerWord": 4,
                                            "wordClickDuration": 8,
                                            "wordListenDuration": 4,
                                            "paperCutDuration": 8
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                },
                "timestamp": 1752729272847,
                "requestId": "16E3EA2A-9F9F-4AE0-94B9-7E6C304E9AF0"
            })

            // resolve({
            //     code: 0,
            //     message: 'success',
            //     data: {
            //         student: {
            //             id: studentId,
            //             name: `学员${studentId}`,
            //             sn: `SN${studentId.toString().padStart(5, '0')}`,
            //             grade: randomGrade,
            //             school: `学校${Math.floor(Math.random() * 5) + 1}`,
            //             trainAccount: Math.random() < 0.5,
            //         },
            //         grade: randomGrade,
            //         actuallyStartTime: actualStartTime.toISOString(),
            //         actuallyEndTime: actualEndTime.toISOString(),
            //         duration: durationMinutes,
            //         trainer: {
            //             id: trainerId,
            //             name: `教练${trainerId}`,
            //             account: `trainer_acc_${trainerId}`,
            //             deliveryGroupId: Math.floor(Math.random() * 1000),
            //         },
            //         wordScore: Math.floor(Math.random() * 101), // 0-100
            //         lessonLearningSummary: lessonLearningSummary,
            //         unitLearningSummary: unitLearningSummary,
            //         groupLearningSummary: groupLearningSummary,
            //     },
            //     timestamp: Date.now(),
            //     requestId: 'requestId_' + Math.random().toString(36).substring(2, 15),
            //     signature: 'signature_' + Math.random().toString(36).substring(2, 15),
            // });
        }, 100);
    });
}